<?php

namespace api\wrapper;

class SmartyWrapper extends Wrapper {

    public static function getSmarty() {
        static $smy = null;
        if ($smy == null)
            $smy = new SmartyWrapper();
        return $smy;
    }

    private function __construct() {
		$this->_object = new \Smarty();
		
		$param = \api\arrayFromIni('SmartyWrapper', __NAMESPACE__);
		
		$this->_object->template_dir = ROOT . $param[APIMODE]['template_dir'];
		$this->_object->compile_dir = ROOT . $param[APIMODE]['compile_dir'];
		$this->_object->config_dir = ROOT . $param[APIMODE]['config_dir'];
		$this->_object->cache_dir = ROOT . $param[APIMODE]['cache_dir'];		
		
		$this->_object->caching = 1;

    }	
	
	public function getInstance() {
		return $this->_object;
	}

	public function setInstance($newSmarty) {
		if($newSmarty instanceof Smarty) {
			$this->_object = $newSmarty;
		}
	}
	
	public function isCached($tpl) {	
	// si TRUE, ne reconstruit pas le cache. si FALSE, reconstruction
	
		$ss = new \api\supersession\SuperSession();
		$var = 'sticky_rebuild_' . $tpl;

		if(isset($ss->$var)) {
			unset($ss->$var);
			$this->_object->clearCache($tpl);		
		}
		
		return $this->_object->isCached($tpl);
	}
}